#include<iostream>
#include<ctime>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#define MAX (pow(2.0, 60))                     //标记最大值
#define C 240
#define TIME 12                                //Miller测试次数
using namespace std;

long long mod_mult(long long a,long long b, long long n) //计算(a*b) mod n
{
    long long s = 0;
    a = a % n;
    while (b) {
        if (b & 1) {
            s += a;
            if (s >= n)
                s -= n;
        }
        a = a << 1;
        if (a >= n)
            a -= n;
        b = b >> 1;
    }

    return s;
}

long long mod_exp(long long a, long long b, long long n) //计算(a^b) mod n
{
    long long d = 1;
    a = a % n;
    while (b >= 1) {
        if (b & 1)
            d = mod_mult(d, a, n);
        a = mod_mult(a, a, n);
        b = b >> 1;
    }
    return d;
}

bool Wintess(long long a, long long n) //以a为基对n进行Miller测试并实现二次探测
{
    long long m, x, y;
    int i, j = 0;
    m = n - 1;
    while (m % 2 == 0) //计算(n-1)=m*(2^j)中的j和m,j=0时m=n-1,不断的除以2直至n为奇数
    {
        m = m >> 1;
        j++;
    }
    x = mod_exp(a, m, n);
    for (i = 1; i <= j; i++) {
        y = mod_exp(x, 2, n);
        if ((y == 1) && (x != 1) && (x != n - 1)) //二次探测
            return true; //返回true时,n是合数

        x = y;
    }
    if (y != 1)
        return true;
    return false;
}

bool miller_rabin(int times, long long n) //对n进行s次的Miller测试
{
    long long a;
    int i;
    if (n == 1)
        return false;
    if (n == 2)
        return true;
    if (n % 2 == 0)
        return false;
    srand(time(NULL));
    for (i = 1; i <= times; i++) {
        a = rand() % (n - 1) + 1;
        if (Wintess(a, n))
            return false;
    }
    return true;
}

long long converse(int b, int n)
{
	long long tot = 0, t = 1;
	while (n--) {
		tot += t;
		t *= b;
	}
	return tot;
}

int main()
{
	int b, n;
	while (cin >> b >> n) {
		long long num = converse(b, n);
		if (miller_rabin(TIME, num))
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
		//cout << num << endl;
	}
	return 0;
}
